#include "CEPath.h"

bool mergePath( char* szDest, int nLen, const char* pszRoot, const char* pszFile )
{
	if ( !szDest || !pszRoot || !pszFile )
		return false;

	szDest[0] = 0;

	strncpy( szDest, pszRoot, nLen - 1 );
	szDest[nLen - 1] = 0;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	if ( szDest[strlen(szDest) - 1] != '\\' )
	{
		strcat( szDest, "\\" );
		szDest[nLen - 1] = 0;
	}
#else
	if ( szDest[strlen(szDest) - 1] != '/' )
	{
		strcat( szDest, "/" );
		szDest[nLen - 1] = 0;
	}
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	if ( pszFile[0] != '\\' )
	{
		strcat( szDest, pszFile );
		szDest[nLen - 1] = 0;
	}
	else
	{
		strcat( szDest, &(pszFile[1]) );
		szDest[nLen - 1] = 0;
	}
#else
	if ( pszFile[0] != '/' )
	{
		strcat( szDest, pszFile );
		szDest[nLen - 1] = 0;
	}
	else
	{
		strcat( szDest, &(pszFile[1]) );
		szDest[nLen - 1] = 0;
	}
#endif

	return true;
}